import requests
import json

from common.helper import get_request_url, get_request_headers


def upload_documents(files):
    response = requests.get(
        url=get_request_url("v1/document/upload"),
        headers=get_request_headers(),
        files=files,
    )
    if response.status_code == 200:
        return json.loads(response.text)
    else:
        print(f"request failed<{response.status_code}>: {response.text}")
        raise Exception("request failed")


if __name__ == "__main__":
    FILE_PATH = 'obsidian全平台同步方案.md'
    files = {'file': (FILE_PATH, open(FILE_PATH, mode='rb'))}
    result = upload_documents(files)
    print(result)
